package com.tbit.uqbike.webmanager.controller;

import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.common.entity.view.Result;
import com.tbit.uqbike.quartz.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.Date;

/**
 * @author jing
 * @date 2020/12/28:55
 * @Description:
 */
@RestController
@Slf4j
@RequestMapping(value = "/quartz")
public class QuartzController {
    @Resource
    private FinancialStatisticsQuartz financialStatisticsQuartz;
    @Resource
    private ClearExpireCouponQuartz clearExpireCouponQuartz;
    @Resource
    private PointQuartz pointQuartz;
    @Resource
    private SundryDataQuartz sundryDataQuartz;
    @Resource
    private ReconciliationQuartz reconciliationQuartz;

    @RequestMapping("/start")
    public JsonResult start(Boolean flag, String day) {
        /**为true就批量删除保存统计的区域redis信息*/
        if (flag) {
            delCache(day);
        }
        financialStatisticsQuartz.statisticalData();
        return JsonResult.ok();
    }

    @RequestMapping("/statisticalData")
    public JsonResult statisticalData123(String accountIds, String startDate, String endDate) {
        financialStatisticsQuartz.statisticalData123(accountIds, startDate, endDate);
        return JsonResult.ok();
    }

    /**
     * 根据品牌id重新预统计
     * @param brandId 品牌id
     * @param startDate 开始时间
     * @param endDate 结束时间
     * @return result
     */
    @GetMapping("/statisticalDataByBrandId")
    public Result<Object> statisticalDataByBrandId(Integer brandId, Date startDate, Date endDate){
        financialStatisticsQuartz.statisticalDataByBrandId(brandId, startDate, endDate);
        return Result.success();
    }


    @RequestMapping("/startByRegion")
    public JsonResult startByRegion(Boolean flag, String day) {
        log.info("分区预统计开始======");
        /**为true就批量删除保存统计的区域redis信息*/
        if (flag) {
            delCache(day);
        }
        financialStatisticsQuartz.statisticalRideLog();
        String str = "成功";
        return JsonResult.ok(str);
    }

    @RequestMapping("/delCache")
    public JsonResult delCache(String day) {
        /**为true就批量删除保存统计的区域redis信息*/
        financialStatisticsQuartz.batchDelRedis(day);
        return JsonResult.ok();
    }

    @RequestMapping("/clear")
    public JsonResult clear(String day) {
        /**为true就批量删除保存统计的区域redis信息*/
        clearExpireCouponQuartz.clear();
        return JsonResult.ok();
    }

    @RequestMapping("/calibrationPoint")
    public JsonResult calibrationPoint() {
        pointQuartz.calibrationPoint();
        return JsonResult.ok();
    }

    @RequestMapping("/statisticsUser")
    public JsonResult statisticsUser() {
        sundryDataQuartz.statisticsUser();
        return JsonResult.ok();
    }

    @RequestMapping("/statisticsLowVoltage")
    public JsonResult statisticsLowVoltage() {
        sundryDataQuartz.statisticsLowVoltage();
        return JsonResult.ok();
    }

    @RequestMapping("/total")
    public JsonResult total(String accountIds, String startDate, String endDate) throws ParseException {
        //reconciliationQuartz.total(accountIds, startDate, endDate);
        return JsonResult.ok();
    }

    @RequestMapping("/reAccountOrder")
    public JsonResult reAccountOrder(String accountIds, String startDate, String endDate) {
        reconciliationQuartz.reAccountOrder();
        if (true){
            return JsonResult.ok();
        }
        reconciliationQuartz.reAccountOrder(accountIds, startDate, endDate);
        return JsonResult.ok();
    }


    @RequestMapping("/reBrandOrder")
    public JsonResult reBrandOrder(String accountIds, String startDate, String endDate) {
        reconciliationQuartz.reBrandOrder();
        if (true){
            return JsonResult.ok();
        }
        reconciliationQuartz.reBrandOrder(accountIds, startDate, endDate);
        return JsonResult.ok();
    }

    @RequestMapping("/reAccountMonthOrder")
    public JsonResult reAccountMonthOrder(String accountIds, String startDate, String endDate) {
        reconciliationQuartz.reAccountMonthOrder(accountIds, startDate, endDate);
        return JsonResult.ok();
    }

    @RequestMapping("/reBrandSerial")
    public JsonResult reBrandSerial(String accountIds, String startDate, String endDate) {
        reconciliationQuartz.reBrandSerial(accountIds, startDate, endDate);
        return JsonResult.ok();
    }

    @RequestMapping("/reAccountMonthType")
    public JsonResult reAccountMonthType(String accountIds, String startDate, String endDate) {
        reconciliationQuartz.reAccountMonthType(accountIds, startDate, endDate);
        return JsonResult.ok();
    }

    @RequestMapping("/excelData")
    public JsonResult excelData(String accountIds, String startDate, String endDate) throws ParseException {
        //reconciliationQuartz.excelData(accountIds, startDate, endDate);
        return JsonResult.ok();
    }

    @RequestMapping("/clearOverdueWaived")
    public JsonResult clearOverdueWaived() {
        clearExpireCouponQuartz.clearOverdueWaived();
        return JsonResult.ok();
    }

}
